<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('主子表提交')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <style>
        input::-webkit-outer-spin-button,
        input::-webkit-inner-spin-button {
            -webkit-appearance: none;
        }

        input[type="number"] {
            -moz-appearance: textfield;

        }

    </style>

</head>


<body class="gray-bg">

<div class="main-content">
    <form id="form-add" class="form-horizontal">

        <input name="companyId" type="hidden" id="companyId"/>
        <input name="programId" type="hidden" id="programId"/>
        <input name="programName" type="hidden" id="programName"/>

        <h4 class="form-header h4"><span class="h4" th:text="${programName}"></span> &nbsp;&nbsp; 流程信息</h4>
        <div class="row">
            <div class="col-sm-12">
                <button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i>
                </button>
                <button type="button" class="btn btn-white btn-sm" onclick="delColumn()"><i class="fa fa-minus">
                    删除</i></button>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </form>
</div>

<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存
        </button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭
        </button>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<script th:src="@{/js/jquery.tmpl.js}"></script>

<script th:inline="javascript">

    /* 模块前缀url */
    var prefix = ctx + "excellenceMonitor";

    /* 初始化 数据 */
    var companyId = [[${companyId}]];
    var programId = [[${programId}]];
    var programName = [[${programName}]];
    // 定义数组
    var arr = new Array();

    /* 初始化 方法 */
    $(function () {
        $("#companyId").val(companyId);
        $("#programId").val(programId);
        $("#programName").val(programName);

        var options = {
            pagination: false,
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sidePagination: "client",
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    width:200,
                    formatter: function (value, row, index) {
                        var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                        return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'manTel',
                    align: 'center',
                    width:200,
                    title: '项目经理及联系方式',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='excellence[%s].manTel' value='%s' autocomplete='off'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'responTel',
                    align: 'center',
                    width:200,
                    title: '项目技术负责人及联系方式',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='excellence[%s].responTel' value='%s' autocomplete='off'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'target',
                    align: 'center',
                    width:200,
                    title: '创优创标目标',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='excellence[%s].target' value='%s' autocomplete='off'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'finishTime',
                    align: 'center',
                    title: '计划完成时间节点',
                    width:200,
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' placeholder='yyyy-MM-dd' name='excellence[%s].finishTime' value='%s' autocomplete='off'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'projectPlanTime',
                    align: 'center',
                    title: '立项计划时间',
                    width:200,
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' placeholder='yyyy-MM-dd' name='excellence[%s].projectPlanTime' value='%s' autocomplete='off'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'declarePlanTime',
                    align: 'center',
                    title: '申报计划时间',
                    width:200,
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' placeholder='yyyy-MM-dd' name='excellence[%s].declarePlanTime' value='%s' autocomplete='off'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'reviewPlanTime',
                    align: 'center',
                    title: '评审计划时间',
                    width:200,
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' placeholder='yyyy-MM-dd' name='excellence[%s].reviewPlanTime' value='%s' autocomplete='off'>", index, value);
                        return html;
                    }
                },
                {
                    field: 'releaseExpectedTime',
                    align: 'center',
                    title: '公布预计时间',
                    width:200,
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' placeholder='yyyy-MM-dd' name='excellence[%s].releaseExpectedTime' value='%s' autocomplete='off'>", index, value);
                        return html;
                    }
                },

                {
                    field: 'note',
                    align: 'center',
                    width:200,
                    title: '备注',
                    formatter: function (value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' name='excellence[%s].note' value='%s' autocomplete='off'>", index, value);
                        return html;
                    }
                }
            ]
        };
        $.table.init(options);
    });

    /* 初始化 日期*/
    function bindDatetimepicker() {
        $("input[name$='finishTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true,
            pickerPosition: 'bottom-right'
        });
        $("input[name$='projectPlanTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true,
            pickerPosition: 'bottom-right'
        });
        $("input[name$='declarePlanTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true,
            pickerPosition: 'bottom-right'
        });
        $("input[name$='reviewPlanTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true,
            pickerPosition: 'bottom-right'
        });
        $("input[name$='releaseExpectedTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true,
            pickerPosition: 'bottom-right'
        });
    }

    /* 添加行 */
    function addColumn() {
        // 获取表格的所有内容行
        var count = $("#" + table.options.id).bootstrapTable('getData').length;
        sub.editColumn();

        $("#" + table.options.id).bootstrapTable('insertRow', {
            index: count,
            row: {
                index: $.table.serialNumber(count),
                manTel: "",
                responTel: "",
                target:"",
                projectPlanTime:"",
                declarePlanTime:"",
                reviewPlanTime:"",
                releaseExpectedTime:"",
                finishTime:"",
                note: "",
            }
        });
        /* 日期初始化 */
        bindDatetimepicker();
    }

    /* 删除行:为了初始化日期,否则日期组件不生效 */
    function delColumn(column) {
        var subColumn = $.common.isEmpty(column) ? "index" : column;
        var ids = $.table.selectColumns(subColumn);
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (ids.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }

        $("#" + table.options.id).bootstrapTable('remove', {field: subColumn, values: ids});

        bindDatetimepicker();
    }

    /* 主子表-提交 */
    function submitHandler() {
        var data = $("#form-add").serializeArray();
        $.operate.saveTab(prefix + '/save', data);
    }

</script>
</body>
</html>
</script>